#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkImageReader2.h>
#include <vtkImageReader2Factory.h>
#include <vtkImageBlend.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer2.h>

int main(int argc, char *argv[])
{
    vtkSmartPointer<vtkImageReader2> reader = vtkImageReader2Factory::CreateImageReader2("img/pic1.png");
    reader->SetFileName("img/pic1.png");
    reader->Update();
    reader->GetOutput()->Print(std::cout);

    vtkSmartPointer<vtkImageCanvasSource2D> canvas = vtkSmartPointer<vtkImageCanvasSource2D>::New();
    canvas->SetScalarTypeToUnsignedChar();
    canvas->SetExtent(0, 1885, 0, 906, 0, 0);
    canvas->SetNumberOfScalarComponents(1);
    canvas->SetDrawColor(0.0);
    canvas->FillBox(0, 1885, 0, 906);
    canvas->SetDrawColor(255.0);
    canvas->FillBox(100, 400, 100, 400);
    canvas->Update();


    vtkSmartPointer<vtkImageBlend> blend = vtkSmartPointer<vtkImageBlend>::New();
    blend->AddInputConnection(reader->GetOutputPort());
    blend->AddInputConnection(canvas->GetOutputPort());
    blend->SetOpacity(0, 0.4);
    blend->SetOpacity(1, 0.6);
    blend->SetBlendMode(0);
    // blend->SetBlendMode(1);
    // blend->SetBlendModeToCompound();
    blend->Update();

    vtkSmartPointer<vtkImageViewer2> viewer = vtkSmartPointer<vtkImageViewer2>::New();
    viewer->SetInputConnection(blend->GetOutputPort());
    viewer->SetSize(512, 512);

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    viewer->SetupInteractor(renderWindowInteractor);
    viewer->Render();
    renderWindowInteractor->Start();
    return EXIT_SUCCESS;
}